﻿using System;

namespace TMLibrary
{
    public static class UIHelper
    {
        public static void SetTimeout(int milliseconds, Action func)
        {
            var timer = new DispatcherTimerContainingAction
            {
                Interval = new TimeSpan(0, 0, 0, 0, milliseconds),
                Action = func
            };
            timer.Tick += _onTimeout;
            timer.Start();
        }
        private static void _onTimeout(object sender, EventArgs arg)
        {
            var t = sender as DispatcherTimerContainingAction;
            t.Stop();
            t.Action();
            t.Tick -= _onTimeout;
        }
    }
    public class DispatcherTimerContainingAction : System.Windows.Threading.DispatcherTimer
    {
         public Action Action { get; set; }
    }
}